<?php
namespace App\Console\Commands;

use GatewayWorker\BusinessWorker;
use Illuminate\Console\Command;
use Workerman\Worker;
use GatewayWorker\Gateway;
use GatewayWorker\Register;


class SocketServer extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     * 划重点 这里就是命令 work:socket [start|stop|reload] [--d]
     */
    protected $signature = 'work:socket {action} {--d}'; 

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'workerman socket';

    /**
     * SocketServer constructor.
     */
    public function __construct()
    {
        parent::__construct();
    }

    public function handle()
    {
        global $argv;
        $action = $this->argument('action');
        $argv[0]='worker:socket';
        $argv[1]=$action;
        $argv[2]=$this->option('d')?'-d':'';

        $gateway = new Gateway('websocket://0.0.0.0:8082');
        new Register('text://0.0.0.0:1238');

        $gateway->name = 'Gateway';
        $gateway->count = 1;
        $gateway->lanIp = '127.0.0.1';
        $gateway->startPort = 10000;
        $gateway->pingInterval = 10;  //10s一次心跳
        $gateway->registerAddress = '127.0.0.1:1238';
        $gateway->pingNotResponseLimit = 3;
        $gateway->pingData = '';
        $worker = new BusinessWorker();
        $worker->eventHandler = 'App\Http\Controllers\Workman\WebSocketController';
        $worker->name = 'Example-Workerman';
        $worker->count = 3;
        $worker->registerAddress = '127.0.0.1:1238';
        Gateway::runAll();
    }

}
